/**
 * 菜品类
 *
 * @project sky-take-out_1
 * @author MECHREVO
 * @date 2023/12/5 14:13:21
 * @version 1.0
 */
package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin/dish")
@RequiredArgsConstructor
public class DishController {
    private final DishService dishService;

    /**
     * 添加菜品
     * @param dishDTO
     * @return
     */
    @PostMapping
    public Result<?> Create(@RequestBody DishDTO dishDTO) {
        dishService.Create(dishDTO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<?> page(DishPageQueryDTO dishPageQueryDTO) {
        PageResult<DishVO> pageResult=dishService.page(dishPageQueryDTO);
        return Result.success(pageResult);
    }
    @DeleteMapping
    public Result<?> deleteById(@RequestParam List<String> ids) {
        dishService.delete(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result infoById(@PathVariable Long id){
        DishVO dishVO=dishService.infoById(id);
        return Result.success(dishVO);
    }

    @PutMapping
    public Result<?> modify(@RequestBody DishDTO dishDTO) {
        dishService.modify(dishDTO);
        return Result.success();
    }
    /**
     * 根据类型查询分类
     * @param categoryId
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("根据类型查询分类")
    public Result list(Integer categoryId) {
        log.info("查询的id{}", categoryId);
        List<DishVO> list = dishService.list(categoryId);
        return Result.success(list);
    }
}
